package com.qf.test;

import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * 连接池操作
 */
public class Demo3 {

    /**
     * 一定要将jedis.close()放到finally代码块中
     */
    @Test
    public void pool(){
        //1. 创建连接池
        JedisPool pool = new JedisPool("192.168.41.41",6379);
        Jedis jedis = null;

        try {
            //2. 获取连接对象
            jedis = pool.getResource();

            //3. 操作
            String json = jedis.get("user");
            System.out.println(json);
        } finally {
            //4. 还连接对象
            jedis.close();
        }
    }
}
